﻿//using System;
//using System.Collections.Generic;
//using System.Data;
//using System.IO;
//using System.Net;
//using System.Net.Mime;
//using System.Text;

//namespace TestSinaAPI
//{
//    public class ReadDataBySinaApi
//    {
//        // Methods
//        internal ReadDataBySinaApi()
//        {
//        }

//        internal static List<Status> DeserializeJsonToListObject(string url)
//        {
//            List<Status> list;
//            using (MemoryStream stream = new MemoryStream())
//            {
//                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<Status>));
//                StreamWriter writer = new StreamWriter(stream);
//                string str = ReadJsonDataToString(url);
//                writer.Write(str);
//                writer.Flush();
//                stream.Position = 0L;
//                list = (List<Status>) serializer.ReadObject(stream);
//                writer.Close();
//                writer.Dispose();
//            }
//            return list;
//        }

//        internal static MediaTypeNames.Image GetAvatarImage(string imgUrl)
//        {
//            return null;
//            //Uri requestUri = new Uri(imgUrl);
//            //return new Bitmap(WebRequest.Create(requestUri).GetResponse().GetResponseStream());
//        }

//        internal static bool PostBlog(string url, string data)
//        {
//            try
//            {
//                HttpWebRequest request2 = WebRequest.Create(url) as HttpWebRequest;
//                CredentialCache cache = new CredentialCache();
//                cache.Add(new Uri(url), "Basic", new NetworkCredential(UserInfo.UserName, UserInfo.Password));
//                request2.Credentials = cache;
//                request2.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(UserInfo.UserName + ":" + UserInfo.Password)));
//                request2.Method = "POST";
//                request2.ContentType = "application/x-www-form-urlencoded";
//                byte[] bytes = Encoding.UTF8.GetBytes(data);
//                request2.ContentLength = bytes.Length;
//                Stream requestStream = request2.GetRequestStream();
//                requestStream.Write(bytes, 0, bytes.Length);
//                requestStream.Close();
//                return true;
//            }
//            catch
//            {
//                return false;
//            }
//        }

//        internal static string ReadJsonDataToString(string url)
//        {
//            CredentialCache cache = new CredentialCache();
//            cache.Add(new Uri(url), "Basic", new NetworkCredential(UserInfo.UserName, UserInfo.Password));
//            WebRequest request = WebRequest.Create(url);
//            request.Credentials = cache;
//            request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(UserInfo.UserNamePassword)));
//            WebResponse response = request.GetResponse();
//            string str = null;
//            using (Stream stream = response.GetResponseStream())
//            {
//                StreamReader reader = new StreamReader(stream, Encoding.UTF8);
//                str = reader.ReadToEnd();
//                reader.Close();
//                reader.Dispose();
//            }
//            response.Close();
//            return str;
//        }

//        internal static DataSet ReadXMLDataToDataSet(string url)
//        {
//            CredentialCache cache = new CredentialCache();
//            cache.Add(new Uri(url), "Basic", new NetworkCredential(UserInfo.UserName, UserInfo.Password));
//            WebRequest request = WebRequest.Create(url);
//            request.Credentials = cache;
//            request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(UserInfo.UserNamePassword)));
//            WebResponse response = request.GetResponse();
//            DataSet set = new DataSet();
//            using (Stream stream = response.GetResponseStream())
//            {
//                StreamReader reader = new StreamReader(stream, Encoding.UTF8);
//                set.ReadXml(reader);
//                reader.Close();
//                reader.Dispose();
//            }
//            response.Close();
//            return set;
//        }

//        internal static string ReadXMLDataToString(string url)
//        {
//            CredentialCache cache = new CredentialCache();
//            cache.Add(new Uri(url), "Basic", new NetworkCredential(UserInfo.UserName, UserInfo.Password));
//            WebRequest request = WebRequest.Create(url);
//            request.Credentials = cache;
//            request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(UserInfo.UserNamePassword)));
//            WebResponse response = request.GetResponse();
//            string str = null;
//            using (Stream stream = response.GetResponseStream())
//            {
//                str = new StreamReader(stream, Encoding.UTF8).ReadToEnd();
//            }
//            response.Close();
//            return str;
//        }
//    }
//}